#!/bin/bash
#   let user input a filename, program will search the filename
#   1.)exist?   2.)file/directory?  3.)file permissions

# 让使用者输入文件名，并判断是否真的输入了字符
echo -e "The program will show you that filename is exist which input by you.\n\n"
read -p "Input a filename:" filename

test -z $filename && echo "You must input a filename" && exit 0

# 判断文件是否存在？
test ! -e $filename && echo "The file $filename NOT exist" && exit 0

# 判断文件类型与属性
test -f $filename && filetype="regular file"
test -d $filename && filetype="directory"
test -r $filename && perm="readable"
test -w $filename && perm="$perm writable"
test -x $filename && perm="$perm executable"

# 输出结果
echo "The file: $filename is a $filetype"
echo "And the permission are: $perm"
exit 0
